/**
 * @description: CustomDashboard PageEditor Types
 * @CodeTextInput: 打上该标签类型的字段，会在编辑器中显示代码输入框
 **/

interface seriesDataArrayItem {
  name: string; //图形名称 @CodeTextInput e.g:`return "Chart Name"`
  yAxisIndex: number; // 0 （左侧纵轴） or 1 （右侧纵轴） 1只有在showRightYAxis为true时生效
  chartColors?: string[]; //图形颜色列表，只有在useArrayMap=true时生效
  chartColor?: string; //图形颜色，只有在useArrayMap为false时生效
  type: string; //图形类型 'line' | 'bar'
  field?: string; //databaseKey下的字段 e.g: "value1"。如果是useArrayMap=true,则field的值为{{item.value1}}
  customValueRender?: string; //自定义渲染函数 e.g: `return data.map(item => item * 100)`
  unit?: string; //单位 e.g: '%'。如果是useArrayMap=true,则unit的值为{{item.unit}}
  labelColors?: string[]; //label颜色列表，只有在useArrayMap为true时生效
  labelColor?: string; //label颜色，只有在useArrayMap为false时生效
  labelBorderColors?: string[]; //label边框颜色列表，只有在useArrayMap=true和type=bar时生效
  labelBorderColor?: string; //label边框颜色，只有在useArrayMap=false和type=bar时生效
  lineShadowColors?: string[]; //折线图阴影颜色列表，只有在useArrayMap=true和type=line时生效
  lineShadowColor?: string; //折线图阴影颜色，只有在useArrayMap=false和type=line时生效
  borderColors?: string[]; //柱子边框颜色列表，只有在useArrayMap=true和type=bar时生效
  borderColor?: string; //柱子边框颜色，只有在useArrayMap=false和type=bar时生效
  barMinHeight?: number; //柱状图最小高度。只有在type=bar时生效。当柱子的值导致高度太小看不清时才需要设置
  radius?: number; //柱状图圆角。只有在type=bar时生效
  stack?: string; //Stack。只有在type=bar时生效。如果有多个柱状图，且stack相同，则会堆叠在一起
  labelPosition?: string; //label位置，一般默认使用top。只有在type=bar时生效。'top' | 'left' | 'right' | 'bottom' | 'inside' | 'insideTop' | 'insideBottom'
}

export interface ChartDataTypes {
  name: string; //组件名称  @CodeTextInput e.g:`return "Chart Name"`
  id: string; //组件id chart_V2ui6
  databaseKey: string; //数据库key
  xAxis: string;
  gridType: string; //'equal' |  'custom'
  gridValue: number | number[]; // 'equal'时为grid的百分比，'custom'时分别为上右下左的百分比值
  useArrayMap?: boolean; //是否使用数组遍历
  height?: number;
  mapConfig?: {
    arrayStr: string;
    colors: string[];
    loadingDatabaseKey?: string;
  };
  seriesDataArray: seriesDataArrayItem[];
  leftYAxisMin: number;
  leftYAxisMax: number;
  showRightYAxis: boolean;
  rightYAxisMin: number;
  rightYAxisMax: number;
}

export interface TabsDataTypes {
  name: string;
  tabList: {
    label: any;
    key: any;
    customVariables?: any[];
  }[];
  activeKey: string;
  eventHandler: {
    action: string;
    databaseKeys?: string[];
  };
  hidden?: string;
}

export interface CardsItemTypes {
  title: string; //标题  @CodeTextInput e.g:`return "Card Name"`
  colSpan?: number;
  useArrayMap?: boolean;
  mapConfig?: {
    arrayStr: string;
    desc?: string;
    title?: string;
    unit?: string;
    fieldKey?: string;
  };
  footer?: string;
  children: {
    title?: string; //标题  @CodeTextInput e.g:`return "Child Name"`
    desc?: string;
    fieldKey: string;
    unit?: string;
    customValueRender?: string;
  }[];
}

export interface CardsDataTypes {
  id: string;
  name: string;
  databaseKey: string;
  cards: CardsItemTypes[];
  hidden?: string;
}

export interface SearchFormDataFieldsItemTypes {
  type: string;
  fieldKey: string;
  label: string;
  placeholder: string;
  initialValue: any;
  value?: any;
  isRequired: boolean;
  selectProps?: {
    optionType: string; //'custom' | 'api';
    customOptionsFormater?: string;
    mode: string; //'multiple' | 'tags' |'default';
    databaseKey?: string;
  };
  projectProps?: {
    mode: string; //'multiple' | 'default';
  };
  dateProps?: {
    picker: string; //'date' | 'week' | 'month' | 'quarter' | 'year';
    specialRange?: string;
    useSpecialRange?: boolean;
  };
  eventHandler?: {
    action: string;
    databaseKeys?: string[];
  };
}

export interface SearchFormDataTypes {
  id: string;
  name: string;
  colSpan: number;
  fields: SearchFormDataFieldsItemTypes[];
  hidden?: string;
  eventHandler?: {
    action: string;
    databaseKeys?: string[];
  };
  queryParamsFormatter?: string;
}

export interface FunnelDataTypes {
  name: string;
  funnelProps: {
    databaseKey: string;
    name: string;
    height: number;
    colSpan?: number;
    width?: number;
    items: {
      name: string;
      key: string;
      formatNumber?: number;
    }[];
  };
  cardProps: {
    showCard: boolean;
    databaseKey: string;
    name: string;
    items: CardsItemTypes[];
  };
  hidden?: string;
}

export interface TableColumnsItemTypes {
  title: string;
  dataIndex: string;
  width: number;
  customRender?: string;
  fieldType?: string;
  fieldProps?: {
    unit?: string;
    dateFormat?: string;
    tagColor?: string;
    tagType?: string;
    linkContext?: string;
    linkUrl?: string;
    linkParams?: {
      key: string;
      value: string;
    }[];
  };
  sorter?: boolean;
  ellipsis?: boolean;
  copyable?: boolean;
}

export interface TableDataTypes {
  id: string;
  name: string;
  databaseKey: string;
  columns: TableColumnsItemTypes[];
  hidden?: string;
  asyncPagination?: boolean;
  pagination?: {
    current: number;
    pageSize: number;
    sort: string | undefined;
  };
  filters?: any[];
  useTabs?: boolean;
  tabListConfig?: {
    tabList: { key: string; label: string; showColumnKeys: string[] }[]; // tab列表
    defaultColumnKeys?: string[]; // 默认显示的列
    defaultCheckedTabs?: string[]; // 默认选中的tab
  };
}

export interface CustomChartSettingsProps {
  id: string;
  name: string;
  databaseKey: string;
  chartOptionsStr: string;
  height?: number;
  hidden?: string;
}

export interface ContainerDataTypes {
  id: string;
  name: string;
  hidden?: string;
  colSpan: number;
  cardType?: string; // 'bordered' | 'inner' | 'ghost';
  columns: {
    title: string;
    colSpan: number;
    type?: string; // 'bordered' | 'inner' | 'ghost';
    children: any[];
  }[];
}
